<?php
class C_proyek extends CI_Controller {
	function __construct(){
		parent::__construct();
		checkLogin();
		$this->load->model('m_proyek');
	}
	function index(){
		$task = secure_post('task');
		switch($task){
			case 'LIST' :
				$this->_list();
				break;
			case 'INSERT' :
				$this->_insert();
				break;
			case 'UPDATE' :
				$this->_update();
				break;
			case 'DELETE' :
				$this->_delete();
				break;
			case 'DEACTIVATE' :
				$this->_deactivate();
				break;
			case 'kelas' :
				$this->_kelas();
				break;
			default :
				$this->load->view('app/v_proyek');
		}
	}
	
	function _list(){
		$data['page'] = numeric_post("page");
		$data['rows'] = numeric_post("rows");
		$data['search'] = nosql_post("search");
		$data['m_cabang_id'] = nosql_post("m_cabang_id");
		$data['proyek_kode'] = nosql_post("proyek_kode");
		$data['proyek_nama'] = nosql_post("proyek_nama");
		$data['proyek_pm'] = nosql_post("proyek_pm");
		$data['proyek_nk'] = nosql_post("proyek_nk");
		$data['proyek_nkppn'] = nosql_post("proyek_nkppn");
		$data['proyek_mulai'] = nosql_post("proyek_mulai");
		$data['proyek_p1'] = nosql_post("proyek_p1");
		$data['proyek_p2'] = nosql_post("proyek_p2");
		echo $this->m_proyek->_list($data);
	}
	
	function _insert(){
		$data = array(
			'm_cabang_id' => $this->input->post('m_cabang_id'), 
			'proyek_kode' => $this->input->post('proyek_kode'), 
			'proyek_nama' => $this->input->post('proyek_nama'), 
			'proyek_pm' => $this->input->post('proyek_pm'), 
			'proyek_nk' => $this->input->post('proyek_nk'), 
			'proyek_kelas' => $this->input->post('proyek_kelas'), 
			'proyek_nkppn' => $this->input->post('proyek_nkppn'), 
			'proyek_mulai' => input_date($this->input->post('proyek_mulai')), 
			'proyek_p1' => input_date($this->input->post('proyek_p1')), 
			'proyek_p2' => input_date($this->input->post('proyek_p2')), 
			  
			'proyek_insert_user'	=>$_SESSION[SESSION_USERID],
			'proyek_insert_date'=> date("Y-m-d h:i:s"));
		$this->m_proyek->_insert($data);
		echo 1;
	}
	
	function _update(){
		$proyek_id = $this->input->post('proyek_id');
		$data = array(
			'm_cabang_id' => $this->input->post('m_cabang_id'), 
			'proyek_kode' => $this->input->post('proyek_kode'), 
			'proyek_nama' => $this->input->post('proyek_nama'), 
			'proyek_pm' => $this->input->post('proyek_pm'), 
			'proyek_nk' => $this->input->post('proyek_nk'), 
			'proyek_kelas' => $this->input->post('proyek_kelas'), 
			'proyek_nkppn' => $this->input->post('proyek_nkppn'), 
			'proyek_mulai' => input_date($this->input->post('proyek_mulai')), 
			'proyek_p1' => input_date($this->input->post('proyek_p1')), 
			'proyek_p2' => input_date($this->input->post('proyek_p2')), 
			
			'proyek_update_user'	=> $_SESSION[SESSION_USERID],
			'proyek_update_date'=> date("Y-m-d h:i:s"));
		$this->m_proyek->_update($data,$proyek_id);
		echo 1;
 	}
	
	function _delete(){
		$proyek_id= $this->input->post('proyek_id');
		$this->m_proyek->_delete($proyek_id);
		echo 1;
	}
	
	function _deactivate(){
		$proyek_id= $this->input->post('proyek_id');
		$data = array(
			'proyek_active' => 'n'
		);
		$this->m_proyek->_deactivate($data,$proyek_id);
		echo 1;
	}
    
    function _kelas(){
        $array = $this->m_proyek->_kelas();//array("husnu","hutan","setiawan");
        echo json_encode($array);
    }
}